<template>
	<view>
		<view class="search-wrapper  fixed">
			<view class="search-box ">
				<text class="iconfont icon-sousuo"></text>
				<input :placeholder="placeholder" placeholder-style="color:#999;" :focus="focus" :value="inputValue" confirm-type="search" @input="input" @confirm="input" />
				<text class="iconfont icon-cha1" v-if="inputValue != ''" @tap="clearInput"></text>
			</view>
			<view class="btn" :style="'color:' + mobile_head_color + ';'" @tap="input"><lang keywords="搜索"></lang></view>
		</view>

		<view class="list-wrapper tag-list" v-if="!(show_null || (!show_history && !show_hot))">
			<!-- 历史搜索 -->
			<view class="history-list" v-if="!(!show_history || history_search.length === 0)">
				<view class="title">
					<lang keywords="历史搜索"></lang>
					<text class="iconfont icon-shanchu" @tap="deleteHistory"></text>
				</view>
				<view class="list">
					<view class="tag" v-for="(item, index) in history_search" :key="index" @tap="input($event)" :data-value="item">{{ item }}</view>
				</view>
			</view>

			<!-- 热门搜索 -->
			<view class="history-list" v-if="!(show_null || !show_hot)">
				<view class="title">
					<block v-if="hot_key && hot_key.key_list && hot_key.key_list.length > 0"><lang keywords="热门搜索"></lang></block>
					<view v-if="hot_key && hot_key.key_list && hot_key.key_list.length > 10" @tap="changeHotList">
						<lang class="iconfont mr5" keywords="换一批"></lang>
						<text class="iconfont icon-huanyizu"></text>
					</view>
				</view>
				<view class="list">
					<view class="tag" v-for="(item, index) in hotList" :key="index" @tap="input($event)" :data-value="item">{{ item }}</view>
				</view>
			</view>
		</view>

		<view class="list-wrapper relate-list" v-if="!(relate_list.length == 0 || shopList.length > 0)">
			<view class="item border-b" v-for="(relateshop, index) in relate_list" :key="index" @tap="goShop($event)" :data-index1="index" data-list="relate_list">
				<view class="img-wrapper" style="width:68px;height:48px;"><image :src="relateshop.image"></image></view>

				<view class="content-box">
					<view class="name">
						<text :class="item.is_high ? 'color' : ''" v-for="(item, index2) in relateshop.name_arr" :key="index2">{{ item.value }}</text>
					</view>
					<view class="info">
						<lang keywords="评分X1" :X1="relateshop.star"></lang>
						<text>|</text>
						<block v-if="relateshop.is_new == 1 || relateshop.month_sale_count > 0">
							<block v-if="relateshop.is_new == 1"><lang keywords="新店入驻"></lang></block>
							<block v-else><lang keywords="已售X1" :X1="relateshop.month_sale_count"></lang></block>
							<text>|</text>
						</block>
						<text>{{ relateshop.range }}</text>
					</view>
				</view>
			</view>
		</view>

		<view class="list-wrapper relate-list result-list" v-if="shopList.length > 0 || filterClick">
			<view class="filter-box fixed border-b">
				<view class="filter ">
					<view
						class="type-item"
						:style="filterTag === 'allType' ? 'color:' + mobile_head_color + ';font-weight: bold;' : ''"
						@click.stop="openMask($event)"
						data-tag="allType"
					>
						{{ filterParam.cat.cat_name }}
						<text :class="'iconfont ' + (showMask ? 'icon-jiantou1' : 'icon-xiala')"></text>
					</view>
					<view
						class="type-item"
						:style="filterTag === 'sort' ? 'color:' + mobile_head_color + ';font-weight: bold;' : ''"
						@click.stop="openMask($event)"
						data-tag="sort"
					>
						{{ filterParam.sort.name }}
						<text :class="'iconfont ' + (showMask ? 'icon-jiantou1' : 'icon-xiala')"></text>
					</view>
					<view
						class="type-item dispatch"
						:style="filterTag === 'dispatch' ? 'color:' + mobile_head_color + ';font-weight: bold;' : ''"
						@click.stop="openMask($event)"
						data-tag="dispatch"
					>
						<lang keywords="筛选"></lang>
						<view class="block-in num-box" v-if="multipleDiscountNum > 0">
							<view class="block-in left" :style="'background:' + mobile_head_color"></view>
							<view class="block-in right" :style="'color:' + mobile_head_color">{{ multipleDiscountNum }}</view>
						</view>
						<text :class="'iconfont ' + (showMask ? 'icon-jiantou1' : 'icon-xiala')"></text>
					</view>
				</view>
			</view>
			<scroll-view
				scroll-y="true"
				:style="'height:100%;background:' + (shopList.length == 0 ? '#fff' : '#f4f4f4')"
				:scroll-top="scrollTop"
				bindscrolltolower="scrollToBottom"
			>
				<shopItem class="shop_item" v-for="shop in shopList" :key="shop.store_id" :shop="shop" 
									:cartNum="store_num[shop.store_id] ? store_num[shop.store_id] : '0' "></shopItem>
			</scroll-view>
		</view>

		<view :class="'mask ' + (showMask ? 'active' : '')" @click.stop="closeMask" v-if="shop_type">
			<view :class="'mask-content ' + (showMask ? 'active' : '')">
				<!-- 全部分类 -->
				<view class="all-type" v-if="filterTag == 'allType'">
					<scroll-view class="nav-box" style="height:270px;" scroll-y="true">
						<view class="nav">
							<view
								:style="category_fir_index == index ? 'color:' + mobile_head_color : ''"
								v-for="(item, index) in shop_type.category_list"
								:key="index"
								@click.stop="selectType($event)"
								:data-index="index"
								data-name="category_fir_index"
							>
								<text>{{ item.cat_name }}</text>
								<text class="iconfont icon-jiantou" v-if="item.son_list.length > 0"></text>
							</view>
						</view>
					</scroll-view>

					<scroll-view class="content-box" style="height:270px;" scroll-y="true">
						<view class="content">
							<view
								:style="item.active ? 'color:' + mobile_head_color : ''"
								v-for="(item, index) in shop_type.category_list[category_fir_index].son_list"
								:key="index"
								@click.stop="selectSecType($event)"
								:data-index="index"
							>
								<block v-if="index === 0"><lang keywords="全部"></lang></block>
								<text v-else>{{ item.cat_name }}</text>
							</view>
						</view>
					</scroll-view>
				</view>

				<!-- 智能排序 -->
				<view class="sort" v-if="filterTag == 'sort'">
					<view
						:style="'color: ' + (sortIndex == index ? mobile_head_color : '')"
						v-for="(item, index) in shop_type.sort_list"
						:key="index"
						@click.stop="selectType($event)"
						:data-index="index"
						data-name="sortIndex"
					>
						<text>{{ item.name }}</text>
						<text class="iconfont icon-dui" v-if="sortIndex == index"></text>
					</view>
				</view>

				<!-- 配送类型 -->
				<view class="dispatch" v-if="filterTag == 'dispatch'" @click.stop="preventDefault">
					<view class="sort-type-box" v-if="shop_type.type_list.length > 0">
						<view class="sort-type-title">{{ shop_type.type_list_title }}</view>
						<view class="sort-type-list">
							<view class="item" v-for="item in shop_type.type_list" :key="item.type_url" @click="selectTypeMultiple(item.type_url, 'delivery')">
								<text class="left" :style="multipleFilterNew[item.type_url] ? 'background:' + mobile_head_color : ''"></text>
								<text class="right" :style="multipleFilterNew[item.type_url] ? 'color:' + mobile_head_color + ';font-weight: bold;' : ''">{{ item.name }}</text>
							</view>
						</view>
					</view>
					<view class="sort-type-box" v-if="shop_type.special_list.length > 0">
						<view class="sort-type-title">{{ shop_type.special_list_title }}</view>
						<view class="sort-type-list">
							<view class="item" v-for="item in shop_type.special_list" :key="item.special_url" @click="selectTypeMultiple(item.special_url, 'discount')">
								<text class="left" :style="multipleFilterNew[item.special_url] ? 'background:' + mobile_head_color : ''"></text>
								<text class="right" :style="multipleFilterNew[item.special_url] ? 'color:' + mobile_head_color + ';font-weight: bold;' : ''">{{ item.name }}</text>
							</view>
						</view>
					</view>
					<view class="sort-btn-box">
						<view class="btn left resetFilter" @click="resetFilter"><lang keywords="重置"></lang></view>
						<view class="btn right confirmFilter" :style="'background:' + mobile_head_color" @click="confirmFilter">
							<lang keywords="完成"></lang>
							<text class="num" v-if="multipleDiscountNumNew > 0">（<lang keywords="已选"></lang>{{ multipleDiscountNumNew }}）</text>
						</view>
					</view>
				</view>
			</view>
		</view>

		<view class="search-null" v-if="show_null">
			<image src="/static/images/sn_searchnull.png"></image>
			<view><lang keywords="没有搜索到相关商品和店铺"></lang></view>

			<!-- #ifdef MP-WEIXIN || MP-ALIPAY -->
			<view class="paotui" v-if="showPaotuiBtn">
				<text class="iconfont icon-waimai"></text>
				<view class="desc">
					<view><lang keywords="找不到店铺与商品？"></lang></view>
					<view class="second"><lang keywords="骑手们帮您全城跑腿"></lang></view>
				</view>
				<navigator class="btn" target="miniProgram" :app-id="wxapp_paotui_appid"><lang keywords="一键下单"></lang></navigator>
			</view>
			<!-- #endif -->
		</view>
	</view>
</template>

<script>
// pages/shop_new/search/search.js
import shopItem from '../../../appComponent/platcommon/shopItem.vue'
import common from '../../../utils/common.js';
var app = getApp();
var _this;

export default {
	components: {shopItem},
	data() {
		return {
			showMask: false,
			filterTag: 'allType',
			scrollTop: '',
			imageHeight: {
				logo: {}
			},
			delivery_address: '',
			// 当前选择的收货地址
			shop_type: '',
			// 全部店铺分类
			category_fir_index: 0,
			category_fir_index_old: 0,
			// 筛选分类一级菜单index
			category_sec_index: 0,
			// 筛选分类二级菜单index
			sortIndex: 0,
			// 排序类型index
			dispatch_index: 0,
			// 配送类型index
			filterClick: false,
			filterParam: {
				cat: '',
				// 分类
				sort: '',
				// 排序
				dispatch: '' // 配送类型
			},
			inputValue: '',
			// 输入框的值
			relate_list: [],
			// 搜索联想
			shopList: [],
			// 店铺列表
			pageIndex: 1,
			pageLoading: true,
			reachBottom: false,
			tag: 'relate_list',
			search_type: 'text',
			// 条形码搜索传barcode，关键字搜索不传或传text
			is_search: false,
			// false只搜索店铺，true搜索的结果中包含商品
			history_search: [],
			// 历史搜索词
			show_history: true,
			// 是否显示历史关键字
			show_null: false,
			// 是否显示未搜索到结果提示
			hot_key: '',
			//热门搜索关键字库
			hotList: [],
			// 实际要显示的热门搜索关键字组
			show_hot: true,
			// 是否显示热门搜索关键字
			store_num: '',
			timer: '',
			barcode: '',
			showPaotuiBtn: false,
			focus: false,
			placeholder: '请输入商家、商品名称',
			wxapp_paotui_appid: '',
			mobile_head_color: '',
			multipleDiscountNum: 0,
			multipleFilter: {},
			multipleDiscountNumNew: 0,
			multipleFilterNew: {},
			currency: '¥'
		};
	},

	onShow() {
		// 获取缓存----店铺分类列表
		getStorage('shop_type').then(data => {
			if (_this.shop_type == '') {
				getShoptypeList();
			} else {
				var filterParam = {
					// 分类
					cat: _this.shop_type.category_list[0],
					// 排序
					sort: _this.shop_type.sort_list[0],
					// 筛选
					dispatch: {
						['type_url']: '',
						['special_url']: ''
					} 
				};
				_this.filterParam = filterParam
			}
		});
		getCartNum()
	},

	// 生命周期函数--监听页面加载
	onLoad: function(options) {
		_this = this;
		common.setMainColor(_this, config => {
			if (config && config.config.wxapp_paotui_appid && config.config.wxapp_paotui_appid != '') {
				_this.showPaotuiBtn = true
				_this.wxapp_paotui_appid = config.config.wxapp_paotui_appid
			} else {
				_this.showPaotuiBtn = false
			}
		});
		wx.setNavigationBarTitle({
			title: common.changeTxt('搜索')
		});
		_this.placeholder = common.changeTxt('请输入商家、商品名称')
		// 获取缓存---热门搜索关键字
		getStorage('hot_key').then(() => {
			if (_this.hot_key != '') {
				if (_this.hot_key.key_list.length > 10) {
					getaRandomList();
				} else if (_this.hot_key.key_list.length == 0) {
					_this.show_hot = false
				} else {
					_this.hotList = _this.hot_key.key_list
				}
			}
		}); 
		// 获取缓存----历史搜索记录
		getStorage('history_search').then(() => {
			if (_this.history_search.length == 0) {
				_this.show_history = false
			}
		});

		// 获取缓存----当前选择收货地址
		var address = app.globalData.delivery_address;
		if (address) {
			_this.delivery_address = address
		}
		if (options.name) {
			console.log('条形码搜索', options.name, options.key);
			_this.show_history = false
			_this.inputValue = decodeURIComponent(options.name)
			_this.search_type = 'barcode'
			_this.tag = 'shopList'
			_this.is_search = true
			_this.show_hot = false
			_this.barcode = options.key
			getShopList();
		} else {
			_this.focus = true
		}
		wx.getSystemInfo({
			success: function(res) {
				// 店铺logo高
				_this.imageHeight.logo.width = res.windowWidth * 0.2;
				_this.imageHeight.logo.height = (420 * (res.windowWidth * 0.2)) / 700;

				_this.phoneInfo = res
				_this.imageHeight = _this.imageHeight
			}
		});
		common.changeCurrency(this)
	},
	methods: {
		// 阻止点击事件冒泡
		preventDefault () {},
		// 筛选完成按钮
		confirmFilter () {
			_this.multipleFilter = JSON.parse(JSON.stringify(_this.multipleFilterNew))
			_this.multipleDiscountNum = _this.multipleDiscountNumNew
			let deliveryStr = ''
			let discountStr = ''
			for (let i in _this.multipleFilter) {
				if (_this.multipleFilter[i] == 'delivery') {
					deliveryStr = deliveryStr + i + '-'
				} else {
					discountStr = discountStr + i + '-'
				}
			}
			deliveryStr = deliveryStr.slice(0, -1)
			discountStr = discountStr.slice(0, -1)
			
			_this.filterParam.dispatch = {
				['type_url']: deliveryStr,
				['special_url']: discountStr
			}
			_this.showMask = false
			_this.pageIndex = 1
			_this.pageLoading = -1
			_this.reachBottom = false
			
			if(_this.multipleDiscountNum == 0){
				_this.filterTag = '';
			}
			
			getShopList();
		},
		// 筛选重置按钮
		resetFilter () {
			_this.multipleDiscountNumNew = 0
			_this.multipleDiscountNum = 0
			_this.multipleFilterNew = {}
		},
		selectTypeMultiple (name, type) {
			if (_this.multipleFilterNew[name]) {
				_this.$set(_this.multipleFilterNew, name, '');
				delete _this.multipleFilterNew[name]
				_this.multipleDiscountNumNew--
			} else {
				_this.$set(_this.multipleFilterNew, name, type);
				_this.multipleDiscountNumNew++
			}
			console.log('点击选择', _this.multipleFilterNew)
		},

		// 筛选菜单显示
		openMask(e) {
			var filterTag = e.currentTarget.dataset.tag;

			if (filterTag === _this.filterTag && _this.showMask == true) {
				_this.showMask = false;
				_this.multipleDiscountNumNew = _this.multipleDiscountNum
				_this.multipleFilterNew = JSON.parse(JSON.stringify(_this.multipleFilter))
			} else {
				_this.showMask = true;
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 200
				});
			}

			_this.showMask = _this.showMask
			_this.filterTag = filterTag
		},

		// 筛选菜单关闭
		closeMask() {
			_this.category_fir_index = _this.category_fir_index_old;
			_this.showMask = false;
			_this.multipleDiscountNumNew = _this.multipleDiscountNum
			_this.multipleFilterNew = JSON.parse(JSON.stringify(_this.multipleFilter))
		},

		// scroll-view的滚动到底部事件
		scrollToBottom(e) {
			if (_this.pageLoading && !_this.reachBottom) {
				_this.reachBottom = true
				getShopList();
			}
		},

		// 选择一级菜单
		selectType(e) {
			var name = e.currentTarget.dataset.name;
			var index = e.currentTarget.dataset.index;

			if (name == 'sortIndex') {
				_this.filterParam.sort = _this.shop_type.sort_list[index];
			}
			
			_this[name] = index
			_this.filterParam = _this.filterParam
			_this.filterClick = true

			if (!_this.shop_type.category_list[index] || !_this.shop_type.category_list[index].son_list || name != 'category_fir_index') {
				_this.showMask = false
				_this.pageIndex = 1
				_this.pageLoading = -1
				_this.reachBottom = false

				getShopList();
			}
		},

		// 选择二级菜单
		selectSecType(e) {
			var index = e.currentTarget.dataset.index;
			var list = _this.shop_type.category_list[_this.category_fir_index].son_list;

			if (list) {
				console.log('11111111', _this.shop_type.category_list[_this.category_fir_index_old].son_list, _this.category_sec_index);
				_this.shop_type.category_list[_this.category_fir_index_old].son_list[_this.category_sec_index].active = false;
				_this.shop_type.category_list[_this.category_fir_index].son_list[index].active = true;

				_this.filterParam.cat = list[index];
				_this.shop_type = _this.shop_type;
				_this.showMask = false;
				_this.category_fir_index_old = _this.category_fir_index;
				_this.category_sec_index = index;
				_this.filterParam = _this.filterParam;
				_this.pageIndex = 1;
				_this.pageLoading = -1;
				_this.reachBottom = false;
				_this.filterClick = true;

				getShopList();
			}
		},

		// input事件
		input(e) {
			clearTimeout(_this.timer);
			var inputValue = e.type == 'input' ? e.detail.value : _this.inputValue;

			if (e.currentTarget.dataset.value != undefined) {
				inputValue = e.currentTarget.dataset.value;
			}

			if (inputValue != '') {
				var list,
					tag,
					is_search = '';
				var search_type = _this.search_type;
				var filterParam = {
					cat: _this.shop_type.category_list[0],
					// 分类
					sort: _this.shop_type.sort_list[0],
					// 排序
					dispatch: {
						['type_url']: '',
						['special_url']: ''
					} ,
					// 配送类型
				};

				if (e.type == 'input') {
					// 输入事件
					list = 'shopList';
					tag = 'relate_list';
					(is_search = false), (search_type = 'text');
				} else {
					// confirm 和 tap事件
					list = 'relate_list';
					tag = 'shopList';
					is_search = true; // 缓存搜索关键字，去重

					var history_search = _this.history_search;
					history_search = history_search.filter(item => item != inputValue);
					history_search.unshift(inputValue);
					wx.setStorage({
						key: 'history_search',
						data: history_search
					});
				}

				_this.show_history = false
				_this.show_hot = false
				_this.show_null = false
				_this.inputValue = inputValue
				_this.pageIndex = 1
				_this.pageLoading = -1
				_this.reachBottom = false
				_this.tag = tag
				_this.is_search = is_search
				_this.search_type = search_type
				_this[list] = []
				_this.filterParam = filterParam
				_this.category_fir_index = 0
				// 筛选分类一级菜单index
				_this.category_sec_index = 0
				// 筛选分类二级菜单index
				_this.sortIndex = 0
				// 排序类型index
				_this.dispatch_index = 0
				// 配送类型index
				_this.filterClick = false
				_this.showMask = false

				_this.timer = setTimeout(() => {
					getShopList();
				}, 500);
			} else {
				// 更新历史关键字
				getStorage('history_search');

				_this.inputValue = ''
				_this.relate_list = []
				_this.shopList = []
				_this.show_history = true
				_this.show_hot = true
				_this.show_null = false
			}
		},

		clearInput() {
			// 更新历史关键字
			getStorage('history_search');

			_this.inputValue = ''
			_this.relate_list = []
			_this.shopList = []
			_this.show_history = true
			_this.show_hot = true
			_this.show_null = false
			_this.showMask = false
			_this.filterClick = false
			_this.search_type = 'text'
			_this.barcode = ''
			_this.focus = true
			
			_this.multipleDiscountNum = 0
			_this.multipleFilter = {}
			_this.multipleDiscountNumNew = 0
			_this.multipleFilterNew = {}
		},

		// 查看更多商品
		showMoreGoods(e) {
			var index = e.currentTarget.dataset.index;
			_this.shopList[index].showMore = !_this.shopList[index].showMore;
		},

		// 删除历史搜索记录
		deleteHistory() {
			wx.removeStorage({
				key: 'history_search',
				success: res => {
					_this.history_search = []
					_this.show_history = false
				}
			});
		},

		// 跳转到对应店铺
		goShop(e) {
			var store = _this[e.currentTarget.dataset.list][e.currentTarget.dataset.index1];

			if (e.currentTarget.dataset.index2 != undefined) {
				var goods = store.goods_list[e.currentTarget.dataset.index2];
				wx.navigateTo({
					url:
						'/pages/shop_new/shopDetail/shopDetail?store_id=' +
						store.store_id +
						'&backgroundColor=' +
						store.shop_fitment_color +
						'&frontColor=' +
						store.shop_fitment_front_color +
						'&sort_id=' +
						goods.sort_id +
						'&goods_id=' +
						goods.goods_id
				});
			} else {
				wx.navigateTo({
					url:
						'/pages/shop_new/shopDetail/shopDetail?store_id=' +
						store.store_id +
						'&backgroundColor=' +
						store.shop_fitment_color +
						'&frontColor=' +
						store.shop_fitment_front_color
				});
			}
		},

		// 换一换热门搜素关键字
		changeHotList() {
			getaRandomList();
		}
	}
};
const getShopList = () => {
	var tag = _this.tag;
	var hot_key = wx.getStorageSync('hot_key');
	var param = {
		lng: _this.delivery_address.lng,
		lat: _this.delivery_address.lat,
		page: _this.pageIndex,
		cat_url: _this.filterParam.cat.cat_url,
		sort_url: _this.filterParam.sort.sort_url,
		type_url: _this.filterParam.dispatch['type_url'],
		special_url: _this.filterParam.dispatch['special_url'],
		key: _this.barcode == '' ? _this.inputValue : _this.barcode,
		is_search: _this.is_search,
		search_type: _this.search_type
	};
	console.log('搜索参数', param);

	if (hot_key) {
		param.hot_keywords = hot_key.key_list;
		param.hot_keywords_time = hot_key.time;
	}

	common.post('Shop_new&a=ajax_list', param, data => {
		wx.hideToast();
		console.log('店铺列表', data, param, tag);

		if (data) {
			data.store_list.map(item => {
				item.showMore = false;
				return item;
			});

			if (data.hot_keywords_time) {
				wx.setStorage({
					key: 'hot_key',
					data: {
						key_list: data.hot_keywords,
						time: data.hot_keywords_time
					}
				});
			}

			if (_this.pageIndex == 1) {
				_this[tag] = [];
			}

			if (tag == 'shopList' && _this.pageIndex == 1 && data.store_list.length == 0) {
				_this.show_null = true
			} else {
				_this.show_null = false
			}

			_this[tag] = _this[tag].concat(data.store_list)
			_this.pageLoading = data.has_more == true
			_this.pageIndex = data.has_more == true ? _this.pageIndex + 1 : _this.pageIndex
			_this.reachBottom = false

			console.log('店铺列表22222', _this.shopList, _this.show_hot, _this.show_hot);
		}
	});
};
// 获取缓存
const getStorage = key => {
	return new Promise((resolve, reject) => {
		// 更新历史关键字
		wx.getStorage({
			key: key,
			success: res => {
				_this[key] = res.data

				resolve(res.data);
			},
			fail: () => {
				resolve();
			}
		});
	});
}; 
// 获取店铺分类列表
const getShoptypeList = () => {
	common.post('Shop_new&a=getCategoryType', {}, data => {
		if (data) {
			data.category_list.map(item => {
				var obj = {
					cat_name: item.cat_name,
					cat_url: item.cat_url,
					active: false
				};

				if (item.son_list) {
					item.son_list.map((i, index) => {
						i.active = false;
						return i;
					});
					item.son_list.unshift(obj);
				} else {
					item.son_list = [obj];
				}

				return item;
			});
			var filterParam = {
				cat: data.category_list[0],
				// 分类
				sort: data.sort_list[0],
				// 排序
				dispatch: {
					['type_url']: '',
					['special_url']: ''
				} // 配送类型
			};

			_this.shop_type = data
			_this.filterParam = filterParam

			wx.setStorage({
				key: 'shop_type',
				data: data
			});
		}
	});
};
const getaRandomList = () => {
	var arr = [].concat(_this.hot_key.key_list);
	var hotList = [];
	var ranNum = 10;

	for (var i = 0; i < ranNum; i++) {
		var ran = Math.floor(Math.random() * arr.length);
		hotList.push(arr[ran]);
		arr.splice(ran, 1);
	}

	_this.hotList = hotList
};
// 获取购物车数量
const getCartNum = () => {
	if (!app.globalData.is_login) {
		return
	}
	common.post('Cart&a=storeNum', {}, function(data){
		console.log('购物车各店铺商品数量', data)
		_this.store_num = data
	})
}
</script>
<style>
/* pages/shop_new/search/search.css */

.mr5 {
	margin-right: 5px;
}
.pt5 {
	padding-top: 5px;
}
.border-t {
	position: relative;
}
.border-b::after {
	content: '';
	position: absolute;
	bottom: 0;
	left: 0;
	height: 1rpx;
	width: 100%;
	background: #e5e5e5;
	transform: scaleY(0.5);
}
.border-t::after {
	content: '';
	position: absolute;
	top: 0;
	left: 0;
	height: 1rpx;
	width: 100%;
	background: #e5e5e5;
	transform: scaleY(0.5);
}

page {
	width: 100%;
	height: 100%;
	background: #fff;
	position: relative;
}

.search-wrapper {
	padding: 10px 10px 0;
	display: flex;
	background: #fff;
}
.search-wrapper.fixed {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: 999;
}
.search-wrapper .search-box {
	background: #f5f5f5;
	border-radius: 5rpx;
	font-size: 15px;
	color: #333;
	display: flex;
	align-items: center;
	padding: 10px 0 10px 10px;
	box-sizing: border-box;
	height: 35px;
	flex: 1;
}
.search-wrapper .search-box input {
	flex: 1;
}
.search-wrapper .search-box .icon-sousuo {
	margin-right: 10rpx;
	color: #999;
	font-size: 15px;
}
.search-wrapper .search-box .icon-cha1 {
	color: #999;
	padding: 20rpx;
}
.search-wrapper .btn {
	font-size: 15px;
	color: #06c1ae;
	height: 35px;
	line-height: 35px;
	margin-left: 10px;
}

.list-wrapper {
	width: 100%;
	height: 100%;
	background: #fff;
	padding: 45px 10px 0;
	box-sizing: border-box;
}
.tag-list .title {
	font-size: 15px;
	color: #333;
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 10px 0;
}
.tag-list .title .iconfont {
	color: #999;
	padding: 5px;
}
.tag-list .list {
	display: flex;
	flex-wrap: wrap;
}
.tag-list .list .tag {
	font-size: 14px;
	margin: 0 10px 10px 0;
	background: #f5f5f5;
	color: #666;
	padding: 8px 15px;
	border-radius: 2px;
}
.tag-list .list .color {
	color: #fb5047;
	background: #ffedec;
}

.relate-list {
	padding: 45px 0 0 10px;
}
.relate-list .item {
	display: flex;
	padding: 10px 10px 10px 0;
	position: relative;
}
.relate-list .item .img-wrapper {
	height: 43px;
	width: 63px;
	margin-right: 10px;
	flex-shrink: 0;
	position: relative;
}
.relate-list .item image {
	height: 100%;
	width: 100%;
	display: block;
	border-radius: 2px;
}
.relate-list .item .content-box {
	display: flex;
	flex-direction: column;
	justify-content: space-around;
}
.relate-list .item .name {
	font-size: 14px;
	color: #333;
	margin-bottom: 5px;
}
.relate-list .item .name .color {
	color: #999;
}
.relate-list .item .info {
	font-size: 12px;
	color: #666;
}
.relate-list .item .info text {
    margin-right: 5px;
	white-space: nowrap;
}

.result-list {
	background: #f3f3f3;
	padding: 90px 0 0;
}
.filter-box.fixed {
	position: fixed;
	left: 0;
	right: 0;
	top: 45px;
	z-index: 999;
}
.filter {
	height: 45px;
	display: flex;
	justify-content: space-between;
	font-size: 15px;
	color: #999;
	padding: 0 10px;
	background: #fff;
}
.filter .type-item {
	height: 100%;
	line-height: 45px;
}
.filter .iconfont {
	margin-left: 10rpx;
}
.filter .active {
	color: #333;
}

.filter .dispatch {
	display: flex;
	align-items: center;
}

.filter .dispatch .num-box {
	display: flex;
	align-items: center;
	width: 16px;
	height: 16px;
	margin-left: 2px;
}

.filter .dispatch .num-box .left {
	width: 100%;
	height: 100%;
	background: red;
	opacity: 0.12;
	border-radius: 50%;
}
.filter .dispatch .num-box .right {
	width: 100%;
	height: 100%;
	color: red;
	text-align: center;
	font-size: 12px;
	font-weight: normal;
	line-height: normal;
	margin-left: -16px;
}

.result-list .item {
	margin-bottom: 10px;
	background: #fff;
	padding: 10px;
	box-sizing: border-box;
	position: relative;
	margin-left: 0;
	display: block;
}
.result-list .item:last-child {
	margin-bottom: 0;
}

.result-list .shop_item{
	background: #fff;
	display: block;
}

.mask {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.5);
	height: 0;
	z-index: 99;
}
.mask.active {
	height: 100%;
}
.mask-content {
	background: #fff;
	font-size: 14px;
	transform: translateY(-100%);
	transition: all 0.5s;
	padding-top: 90px;
}
.mask-content.active {
	transform: translateY(0);
}
.all-type {
	display: flex;
	height: 270px;
	overflow: hidden;
	box-sizing: border-box;
}
.all-type .nav-box {
	width: 45%;
}
.all-type .nav {
	padding: 0 10px 15px;
}
.all-type .nav .icon-jiantou {
	font-size: 15px;
}
.all-type .content-box {
	background: #f1f5f5;
}
.all-type .content {
	padding: 0 30px 15px;
}
.all-type .nav view,
.all-type .content view,
.sort view {
	height: 40px;
	line-height: 40px;
}
.all-type .active {
	color: #06c1ae;
}
.sort {
	padding: 0 10px 10px;
}
.sort view {
	display: flex;
	justify-content: space-between;
}

.search-null {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	text-align: center;
	font-size: 14px;
	color: #999;
}
.search-null image {
	width: 100px;
	height: 100px;
}
.search-null .paotui {
	display: flex;
	justify-content: space-between;
	align-items: center;
	border: 1rpx solid #06c1ae;
	width: 640rpx;
	padding: 10px;
	box-sizing: border-box;
	margin-top: 30px;
	color: #06c1ae;
}
.search-null .paotui .iconfont {
	font-size: 40px;
}
.search-null .paotui .desc {
	text-align: left;
	font-size: 28rpx;
}
.search-null .paotui .second {
	font-size: 32rpx;
}
.search-null .paotui .btn {
	background: #06c1ae;
	color: #fff;
	padding: 4px 10px;
	border-radius: 2px;
}

.shop-type {
	margin-top: 5px;
	
}
.shop-type .type-item {
	font-size: 12px;
	color: #E29448 ;
	background: #FDF8E0;
	padding: 1px 4px;
	border-radius: 2px;
	width: 100%;
	white-space: nowrap;
}

.shop-type-list{
	font-size: 12px;
	padding-top: 5px;
	color: #666;
}
.shop-type-list .iconfont{
	font-size: 14px;
	margin-right: 5px;
}

.shop-type-list .type-item {
	margin-right: 5px;
}

/* 发票 */
.invoice {
	color: #06c1ae;
	border: 1rpx solid #c5f3ef;
}

/* 平台首单优惠 平台优惠 */
.system_newuser,
.system_minus {
	color: #aa8023;
	border: 1rpx solid #f3e5c6;
}

/* 打折 部分商品限时优惠  部分商品分类折扣优惠 配送费优惠 店铺首单优惠 店铺优惠 */
.discount,
.isdiscountgoods,
.isdiscountsort,
.delivery,
.newuser,
.delivery_free,
.minus,
.full_gift{
	color: #ff3e4a;
	border: 1rpx solid #fce5e7;
}

.sort-type-box{
	padding-top: 20rpx;
}
.sort-type-box:last-child{
	padding-top: 0;
}

.sort-type-title{
	font-size: 12px;
	color: #999;
	padding: 0 20rpx;
}

.sort-type-list{
	display: flex;
	flex-wrap: wrap;
	padding: 20rpx 0 20rpx 20rpx;
}

.sort-type-list .item{
	height: 36px;
	margin-right: 20rpx;
	margin-bottom: 20rpx;
	position: relative;
	width: -webkit-calc(33.3333% - 20rpx);
	width: calc(33.3333% - 20rpx);
}

.sort-type-list .item .left{
	display: inline-block;
	width: 100%;
	height: 100%;
	background: #bbb;
	opacity: 0.12;
	border-radius: 4rpx;
}

.sort-type-list .item .right{
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	display: inline-block;
	color: #666;
	text-align: center;
	line-height: 36px;
	font-size: 12px;
}
.sort-btn-box{
	border-top: 1px solid #f2f2f2;
	display: flex;
}
.sort-btn-box .btn{
	width: 50%;
	padding: 20rpx 0;
	text-align: center;
}
.sort-btn-box .btn.left{
	color: #999;
}
.sort-btn-box .btn.right{
	color: #fff;
	background: rgb(6, 193, 174);
}

.sort-btn-box .resetFilter, .sort-btn-box .confirmFilter{
	font-size:16px;
}
.sort-btn-box .confirmFilter .num{
	font-size:12px;
}
</style>
